package com.hr.system.controller;

import java.util.List;

import com.hr.common.core.domain.entity.SysUser;
import com.hr.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hr.common.annotation.Log;
import com.hr.common.enums.BusinessType;
import com.hr.system.domain.Salary;
import com.hr.system.service.ISalaryService;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.utils.poi.ExcelUtil;
import com.hr.common.core.page.TableDataInfo;

/**
 * 员工工资管理Controller
 * 
 * @author ruoyi
 * @date 2021-02-26
 */
@Controller
@RequestMapping("/system/salary")
public class SalaryController extends BaseController
{
    private String prefix = "system/salary";

    @Autowired
    private ISalaryService salaryService;

    @RequiresPermissions("system:salary:view")
    @GetMapping()
    public String salary()
    {
        return prefix + "/salary";
    }

//    @RequiresPermissions("system:salary:view")
    @GetMapping("/mySalary")
    public String mySalary(ModelMap modelMap, Salary salary)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        salary.setUserId(sysUser.getUserId().intValue());
        salary.setTenantId(sysUser.getTenantId());
        List<Salary> mySalary = salaryService.selectMySalaryList(salary);
        modelMap.put("mySalary", mySalary);
        return prefix + "/mySalary";
    }

    /**
     * 查询员工工资列表
     */
    @RequiresPermissions("system:salary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Salary salary)
    {
        startPage();
        List<Salary> list = salaryService.selectSalaryList(salary);
        return getDataTable(list);
    }

    /**
     * 导出员工工资列表
     */
    @RequiresPermissions("system:salary:export")
    @Log(title = "员工工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Salary salary)
    {
        List<Salary> list = salaryService.selectSalaryList(salary);
        ExcelUtil<Salary> util = new ExcelUtil<Salary>(Salary.class);
        return util.exportExcel(list, "salary");
    }

    /**
     * 导出员工工资选中项
     */
    @RequiresPermissions("system:salary:export")
    @Log(title = "员工工资", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelected")
    @ResponseBody
    public AjaxResult exportSelected(String ids)
    {
        System.out.println("ids = " + ids);
        List<Salary> list = salaryService.selectSalaryByIds(ids);
        ExcelUtil<Salary> util = new ExcelUtil<Salary>(Salary.class);
        return util.exportExcel(list, "salary");
    }


    /**
     * 新增员工工资
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工工资
     */
    @RequiresPermissions("system:salary:add")
    @Log(title = "员工工资", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Salary salary)
    {
        return toAjax(salaryService.insertSalary(salary));
    }

    /**
     * 修改员工工资
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        System.out.println("id ==================> " + id);
        Salary salary = salaryService.selectSalaryById(id);
        mmap.put("salary", salary);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工工资
     */
    @RequiresPermissions("system:salary:edit")
    @Log(title = "员工工资", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Salary salary)
    {
        return toAjax(salaryService.updateSalary(salary));
    }

    /**
     * 删除员工工资
     */
    @RequiresPermissions("system:salary:remove")
    @Log(title = "员工工资", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(salaryService.deleteSalaryByIds(ids));
    }




}
